﻿<Window
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:interop="clr-namespace:WPFInterop.Interop;assembly=WPFInterop"
    xmlns:interactive3D="clr-namespace:_3DTools;assembly=3DTools"
    xmlns:forms="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
    x:Class="ExampleApplication.MainWindow"
    Title="ExampleApplication" Height="500" Width="500" WindowStartupLocation="CenterScreen"
    >
  <DockPanel>
    <CheckBox x:Name="Debug" DockPanel.Dock="Top" Margin="4">
      Debug (Shows the Win32 control ghost)
    </CheckBox>
    <TabControl VerticalAlignment="Stretch" Height="Auto" IsSynchronizedWithCurrentItem="True">
      <TabItem Header="Introduction">
        <StackPanel>
          <TextBlock VerticalAlignment="Stretch" TextWrapping="Wrap">
            This is a simple example demonstrating the 2D and 3D functionality Win32 Interop Render.
            <LineBreak/>
            <LineBreak/>
            <Bold>
              Authors:
              <LineBreak/>
              Jeremiah Morrill (jeremiah.morrill@gmail.com)
              <LineBreak/>
              Leslie Godwin (leslie.godwin@gmail.com)
            </Bold>
            <LineBreak/>
          </TextBlock>
          <Border BorderThickness="2" BorderBrush="Blue" Margin="10">
            <Border.Background>
              <SolidColorBrush Color="Gray"/>
            </Border.Background>
            <TextBlock Margin="10" TextWrapping="Wrap">
              This sample is released as public domain.  It is distributed in the hope that
              it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
              of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
            </TextBlock>
          </Border>
        </StackPanel>
      </TabItem>
      <TabItem Header="2D Example">
        <DockPanel>
          <DockPanel.Background>
            <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
              <GradientStop Color="#FF00B3E0" Offset="0"/>
              <GradientStop Color="#FF114A00" Offset="1"/>
            </LinearGradientBrush>
          </DockPanel.Background>
          <TextBox x:Name="UrlTextBox2D" DockPanel.Dock="Top" Text="file://D:\Dev\NET\3rd Party\DotNetMagic\readme.html"
                   Loaded="UrlTextBox2D_Loaded"
                   KeyDown="UrlTextBox2D_KeyDown"
                   />
          <Border BorderBrush="Blue" BorderThickness="4">
            <interop:Win32HostRenderer x:Name="_WebBrowserHost2D" Debug="{Binding ElementName=Debug, Path=IsChecked}">
              <interop:Win32HostRenderer.ContentControl>
                <forms:WebBrowser Width="400" Height="400"/>
              </interop:Win32HostRenderer.ContentControl>

              <interop:Win32HostRenderer.OpacityMask>
                <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                  <LinearGradientBrush.GradientStops>
                    <GradientStop Offset="0" Color="Black"/>
                    <GradientStop Offset=".8" Color="Transparent"/>
                  </LinearGradientBrush.GradientStops>
                </LinearGradientBrush>
              </interop:Win32HostRenderer.OpacityMask>
            </interop:Win32HostRenderer>
          </Border>
          <Image DockPanel.Dock="Bottom" Height="100" Source="{Binding ElementName=_WebBrowserHost2D, Path=Visual}"/>
        </DockPanel>
      </TabItem>
      <TabItem Header="3D Example">
        <Grid>
          <Grid.Resources>
            <MeshGeometry3D x:Key="PlaneMesh" Positions="-1,1,0 -1,-1,0 1,-1,0 1,1,0" TextureCoordinates="0,0 0,1 1,1 1,0" TriangleIndices="0,1,2,0,2,3" Normals="0,0,1 0,0,1 0,0,1 0,0,1"/>
          </Grid.Resources>
          <Grid.Background>
            <LinearGradientBrush EndPoint="1,0.5" StartPoint="0,0.5">
              <GradientStop Color="#FF9FB3E0" Offset="0"/>
              <GradientStop Color="#FF114A5B" Offset="1"/>
            </LinearGradientBrush>
          </Grid.Background>
          <interactive3D:TrackballDecorator>
            <interactive3D:Interactive3DDecorator x:Name="decorator">
              <Viewport3D>
                <!-- Add a camera to the scene -->
                <Viewport3D.Camera>
                  <PerspectiveCamera Position="0,0,6">
                  </PerspectiveCamera>
                </Viewport3D.Camera>

                <!-- The Interactive 3D shapes -->
                <interactive3D:InteractiveVisual3D Geometry="{StaticResource PlaneMesh}">
                  <interactive3D:InteractiveVisual3D.Visual>
                    <interop:Win32HostRenderer Debug="{Binding ElementName=Debug, Path=IsChecked}">
                      <interop:Win32HostRenderer.ContentControl>
                        <forms:WebBrowser Width="400" Height="400" Url="http://www.bing.com"/>
                      </interop:Win32HostRenderer.ContentControl>
                    </interop:Win32HostRenderer>
                  </interactive3D:InteractiveVisual3D.Visual>

                  <interactive3D:InteractiveVisual3D.Transform>
                    <Transform3DGroup>
                      <RotateTransform3D>
                        <RotateTransform3D.Rotation>
                          <AxisAngleRotation3D Axis="0 0 0" Angle="0"/>
                        </RotateTransform3D.Rotation>
                      </RotateTransform3D>
                      <TranslateTransform3D OffsetZ="1"/>

                    </Transform3DGroup>
                  </interactive3D:InteractiveVisual3D.Transform>
                </interactive3D:InteractiveVisual3D>
                <interactive3D:InteractiveVisual3D Geometry="{StaticResource PlaneMesh}">
                  <interactive3D:InteractiveVisual3D.Visual>
                    <interop:Win32HostRenderer Debug="{Binding ElementName=Debug, Path=IsChecked}">
                      <interop:Win32HostRenderer.ContentControl>
                        <forms:WebBrowser Width="400" Height="400" Url="http://www.google.com"/>
                      </interop:Win32HostRenderer.ContentControl>
                    </interop:Win32HostRenderer>
                  </interactive3D:InteractiveVisual3D.Visual>

                  <interactive3D:InteractiveVisual3D.Transform>
                    <Transform3DGroup>
                      <TranslateTransform3D OffsetZ="1"/>
                      <RotateTransform3D>
                        <RotateTransform3D.Rotation>
                          <AxisAngleRotation3D Axis="0 1 0" Angle="90"/>
                        </RotateTransform3D.Rotation>
                      </RotateTransform3D>

                    </Transform3DGroup>
                  </interactive3D:InteractiveVisual3D.Transform>
                </interactive3D:InteractiveVisual3D>

                <!-- Lights -->
                <ModelVisual3D>
                  <ModelVisual3D.Content>
                    <Model3DGroup>
                      <Model3DGroup.Children>
                        <AmbientLight Color="#FFFFFFFF"/>
                      </Model3DGroup.Children>
                    </Model3DGroup>
                  </ModelVisual3D.Content>
                </ModelVisual3D>
              </Viewport3D>
            </interactive3D:Interactive3DDecorator>
          </interactive3D:TrackballDecorator>
        </Grid>
      </TabItem>
    </TabControl>
  </DockPanel>
</Window>
